package com.vessel.decoration.mvp.ui.activity.artisan;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.jess.arms.di.component.AppComponent;
import com.vessel.decoration.R;
import com.vessel.decoration.app.base.MySupportActivity;
import com.vessel.decoration.app.base.MySupportAdapter;
import com.vessel.decoration.app.data.entity.TypeListResponse;
import com.vessel.decoration.di.component.DaggerArtisanListComponent;
import com.vessel.decoration.di.module.ArtisanListModule;
import com.vessel.decoration.mvp.contract.ArtisanListContract;
import com.vessel.decoration.mvp.presenter.ArtisanListPresenter;
import com.vessel.decoration.mvp.ui.widget.RefreshLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author Jimq
 * @date 2017/12/3
 */

public class ArtisanListActivity extends MySupportActivity<ArtisanListPresenter>
        implements ArtisanListContract.View {
    @BindView(R.id.swipe_container)
    RefreshLayout mSwipeLayout;
    @BindView(R.id.shop_list)
    ListView mShopList;
    @BindView(R.id.tv_title)
    TextView mTitle;
    @BindView(R.id.tv_right)
    TextView mTitleRight;
    @BindView(R.id.iv_right)
    ImageView mImageRight;

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerArtisanListComponent
                .builder()
                .appComponent(appComponent)
                .artisanListModule(new ArtisanListModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_artisan_list;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        String title = getIntent().getStringExtra("title");
        mTitle.setText(TextUtils.isEmpty(title) ? "精湛技工" : title);
        mTitleRight.setText("全部");
        mTitleRight.setVisibility(View.VISIBLE);
        mImageRight.setVisibility(View.VISIBLE);
        mPresenter.queryTypeList();
        mSwipeLayout.setColorSchemeResources(
                R.color.common_color, R.color.green, R.color.ghostwhite, R.color.firebrick);
        mSwipeLayout.setOnRefreshListener(mPresenter);
//        mSwipeLayout.setOnLoadListener(mPresenter);
        mShopList.setOnItemClickListener(mPresenter);
    }

    @Override
    public void updateLoading(boolean show) {
        if (show) {
            mSwipeLayout.setRefreshing(false);
        } else {
            mSwipeLayout.setLoading(false);
        }
    }

    @Override
    public void setAdapter(MySupportAdapter adapter) {
        mShopList.setAdapter(adapter);
    }

    @OnClick({R.id.tv_right, R.id.iv_left})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_right:
                mPresenter.showPop(view);
                break;
            case R.id.iv_left:
                killMyself();
                break;
        }
    }

    @Override
    public void updatePop(List<TypeListResponse.TypesBean> list, int index) {
        mTitleRight.setText(list.get(index).getTypeName());
        mPresenter.getArtisanList(true);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(String message) {

    }

    @Override
    public void launchActivity(Intent intent) {

    }

    @Override
    public void killMyself() {
        finish();
    }
}
